package Lee_code;

import java.util.*;

public class Lee_503
{
    public int[] nextGreaterElements(int[] nums) {

        //边界判断
        if(nums == null || nums.length <= 1) {
            return new int[]{-1};
        }
        int len = nums.length;
        int[] res = new int[len];
        Arrays.fill(res, -1);
        Deque<Integer> deque= new LinkedList<>();

        deque.push(0);
        for(int i=1; i<(len*2); i++)
        {
            while (!deque.isEmpty()&&nums[deque.peek()]<nums[i])
            {
                res[deque.peek()] = nums[i];
                deque.pop();
            }
            deque.push(i);
        }
        return res;
    }
}
